

*** This do file includes regressions based on the Survey of the Afghan People (SAP) for the paper "Foreign Interventions and Community Cohesion in Times of Conflict"	
*** Author: Sarah Langlotz		
*** Journal: Journal of Development Economics
													

***********************************************************************************************
**************************************Read me **************************************
***********************************************************************************************
*** FOLDER STRUCTURE
/* After downloading the data from the Harvard Dataverse, create the following three folders:
	- "processed"
	- "graphs"
	- "tables"
*/



***	DATA ACCESS
*	Data is publicly available and shared on dataverse.



***	SOFTWARE VERSION
*	Stata/MP 19.0 for Windows (64-bit x86-64), Revision 21 May 2025

*	Please note that rdrobust produces different bandwidths depending on the version. This paper used *!version 7.3.0  09Jun2017  
net install st0366_1, from(http://www.stata-journal.com/software/sj17-2) replace



***	TABLES 
* 	This dofiles created Tables 3, 4 (Panel A), 5 (Panel F), 8


***********************************************************************************
***	Set your directory

local DIR = ""
cap cd "`DIR'"

***********************************************************************************

drop _all
clear matrix
clear mata
set maxvar 10000
set matsize 10000

set more off

clear
use "processed\finaldata_hhlevel_SAP_external.dta"
	
	global short l1lnaid_wb l1vhi log_l1nightlight   


	
********************************************************************************
* TABLE 3 - Panel: Trust (SAP), 2006-2010
********************************************************************************

	cap drop isaf
	gen double isaf = .
	cap drop contest
	gen double contest = .



	cap est drop *

	local Ytrust trust_shura trust_people formtrust_index

	cap est drop *

	foreach Y of varlist `Ytrust' {

    local i = 1
    foreach X of varlist largebase_inbr activebase no_securityprt {

        replace isaf = `X'
        replace contest = l1lnallsigacts

        reghdfe `Y' isaf contest $short [pweight=hhweightAF] if year<2011, absorb(id i.year i.wave_AF) cluster(districtcode)
        estadd local lag "No"
		estadd local controls "Yes"
        estadd local pyfe "Yes"
        estadd local restr "Yes"
        quietly summarize year if e(sample)
        local firstyear = r(min)
        local lastyear  = r(max)
        estadd local years "`firstyear'-`lastyear'"
        est store est1_`i'_`Y'

        replace isaf = l1`X'
        replace contest = l1lnallsigacts

        reghdfe `Y' isaf contest $short [pweight=hhweightAF] if year<2011, absorb(id i.year i.wave_AF) cluster(districtcode)
		estadd local lag "Yes"
		estadd local controls "Yes"
        estadd local pyfe "Yes"
        estadd local restr "Yes"
        quietly summarize year if e(sample)
        local firstyear = r(min)
        local lastyear  = r(max)
        estadd local years "`firstyear'-`lastyear'"
        est store est2_`i'_`Y'

        local ++i
    }

    esttab est1_1_`Y' est2_1_`Y' est1_2_`Y' est2_2_`Y' est1_3_`Y' est2_3_`Y' ///
        using "tables/Panel_AF_`Y'.tex", fragment booktabs se(3) b(3) ///
        star starlevels(* 0.10 ** 0.05 *** 0.01) replace ///
        mlabel(none) style(fixed) keep(isaf) order(isaf) ///
        varlabel(isaf "ISAF") ///
        stats(r2_a N years lag, fmt(3 0 0) label( "Adj. R^2" "Observations" "Years" "\hline Lagged")) ///
        nonumbers nogaps noabbr nolines nomtitle nonote
}


********************************************************************************
* TABLE 4 - Panel: Dispute shura (SAP, ANQAR), 2007-2009 (only Panel A)
********************************************************************************

	cap est drop *

	foreach Y of varlist dispute_shura {

    local i = 1
    foreach X of varlist ma_largebase_inbr activebase no_securityprt {

        replace isaf = `X'
        replace contest = l1lnallsigacts

        reghdfe `Y' isaf contest $short [pweight=hhweightAF] if year<2011, absorb(id i.year i.wave_AF) cluster(districtcode)
        estadd local lag "No"
		estadd local controls "Yes"
        estadd local pyfe "Yes"
        estadd local restr "Yes"
        quietly summarize year if e(sample)
        local firstyear = r(min)
        local lastyear  = r(max)
        estadd local years "`firstyear'-`lastyear'"
        est store est1_`i'_`Y'

        replace isaf = l1`X'

        reghdfe `Y' isaf contest $short [pweight=hhweightAF] if year<2011, absorb(id i.year i.wave_AF) cluster(districtcode)
		estadd local lag "Yes"
		estadd local controls "Yes"
        estadd local pyfe "Yes"
        estadd local restr "Yes"
        quietly summarize year if e(sample)
        local firstyear = r(min)
        local lastyear  = r(max)
        estadd local years "`firstyear'-`lastyear'"
        est store est2_`i'_`Y'

        local ++i
    }

    esttab est1_1_`Y' est2_1_`Y' est1_2_`Y' est2_2_`Y' est1_3_`Y' est2_3_`Y' ///
        using "tables/Panel_AF_`Y'.tex", fragment booktabs se(3) b(3) ///
        star starlevels(* 0.10 ** 0.05 *** 0.01) replace ///
        mlabel(none) style(fixed) keep(isaf) order(isaf) ///
        varlabel(isaf "ISAF") ///
        stats(r2_a N years, fmt(3 0 0) label( "Adj. R$^2$" "Observations" "Years")) ///
        nonumbers nogaps noabbr nolines nomtitle nonote
}
			
********************************************************************************
* TABLE 5 - Panel: Counterinsurgency, 2005-2010 (only Panel F)
********************************************************************************
	
	cap est drop *

	foreach Y of varlist travel_fear {

    local i = 1
    foreach X of varlist largebase_inbr  activebase no_securityprt {

        replace isaf = `X'
        replace contest = l1lnallsigacts

        reghdfe `Y' isaf contest [pweight=hhweightAF] if year<2011, absorb(id i.year i.wave_AF) cluster(districtcode)
        estadd local lag "No"
		estadd local controls "Yes"
        estadd local pyfe "Yes"
        estadd local restr "Yes"
        quietly summarize year if e(sample)
        local firstyear = r(min)
        local lastyear  = r(max)
        estadd local years "`firstyear'-`lastyear'"
        est store est1_`i'_`Y'

        replace isaf = l1`X'

        reghdfe `Y' isaf contest [pweight=hhweightAF] if year<2011, absorb(id i.year i.wave_AF) cluster(districtcode)
		estadd local lag "Yes"
		estadd local controls "Yes"
        estadd local pyfe "Yes"
        estadd local restr "Yes"
        quietly summarize year if e(sample)
        local firstyear = r(min)
        local lastyear  = r(max)
        estadd local years "`firstyear'-`lastyear'"
        est store est2_`i'_`Y'

        local ++i
    }

    esttab est1_1_`Y' est2_1_`Y' est1_2_`Y' est2_2_`Y' est1_3_`Y' est2_3_`Y' ///
        using "tables\Panel_AF_`Y'.tex", fragment booktabs se(3) b(3) ///
        star starlevels(* 0.10 ** 0.05 *** 0.01) replace ///
        mlabel(none) style(fixed) keep(isaf) order(isaf) ///
        varlabel(isaf "ISAF") ///
        stats(r2_a N  years lag, fmt(3 0 0 0) label( "Adj. R$^2$" "Observations" "Years" "\hline Lagged")) ///
        nonumbers nogaps noabbr nolines nomtitle nonote
}


********************************************************************************
* TABLE 8 - Panel: Confidence (SAP), 2006-2010
********************************************************************************

	local Yconf conf_shura conf_cdc formconf_index satisfied_cdc 

	cap est drop *

	foreach Y of varlist `Yconf' {

    local i = 1
    foreach X of varlist largebase_inbr  activebase no_securityprt {

        replace isaf = `X'
        replace contest = l1lnallsigacts

        reghdfe `Y' isaf contest [pweight=hhweightAF] if year<2011, absorb(id i.year i.wave_AF) cluster(districtcode)
        estadd local lag "No"
		estadd local controls "Yes"
        estadd local pyfe "Yes"
        estadd local restr "Yes"
        quietly summarize year if e(sample)
        local firstyear = r(min)
        local lastyear  = r(max)
        estadd local years "`firstyear'-`lastyear'"
        est store est1_`i'_`Y'

        replace isaf = l1`X'

        reghdfe `Y' isaf contest [pweight=hhweightAF] if year<2011, absorb(id i.year i.wave_AF) cluster(districtcode)
		estadd local lag "Yes"
		estadd local controls "Yes"
        estadd local pyfe "Yes"
        estadd local restr "Yes"
        quietly summarize year if e(sample)
        local firstyear = r(min)
        local lastyear  = r(max)
        estadd local years "`firstyear'-`lastyear'"
        est store est2_`i'_`Y'

        local ++i
    }

    esttab est1_1_`Y' est2_1_`Y' est1_2_`Y' est2_2_`Y' est1_3_`Y' est2_3_`Y' ///
        using "tables\Panel_AF_`Y'.tex", fragment booktabs se(3) b(3) ///
        star starlevels(* 0.10 ** 0.05 *** 0.01) replace ///
        mlabel(none) style(fixed) keep(isaf) order(isaf) ///
        varlabel(isaf "ISAF") ///
        stats(r2_a N years lag, fmt(3 0 0) label( "Adj. R$^2$" "Observations" "Years" "\hline Lagged")) ///
        nonumbers nogaps noabbr nolines nomtitle nonote
}
